package game;

import java.util.ArrayList;

public class AI 
{
	Battle battle;
	ArrayList<Character> enemies;
	ArrayList<Character> friendlies;
	
	public AI (Battle battle)
	{
		this.battle = battle;
		enemies = battle.getEnemies();
		friendlies = battle.getFriendlies();
	}
	
	public void playTurn()
	{
		Character c = battle.getNaPotezu();
		
		if(enemies.contains(c))
		{
			battle.napadni(getWeakest(friendlies));
			battle.prebaciPotez();
		}
		else
		{
			battle.napadni(getWeakest(enemies));
			battle.prebaciPotez();
		}
		
		
	}
	
	private Character getWeakest(ArrayList<Character> list)
	{
		int min = list.get(0).getHealth();
		int index = 0;
		
		for(int i = 0;i < list.size();i++)
		{
			if(list.get(i).getHealth() < min)
			{
				min = list.get(i).getHealth();
				index = i;
			}
		}
		
		return list.get(index);
		
	}
}
